public class Solution388 {
    public int lengthLongestPath(String input) {
        String[] s=input.split("\n");
        int[] f=new int[s.length];
        int[] l=new int[s.length];
        for (int i=0;i<s.length;i++){
            while (s[i].startsWith("\t")){
                f[i]++;
                s[i]=s[i].substring(1);
            }
            l[i]=s[i].length();
        }
        int ans=0;
        int[] stack=new int[s.length];
        for (int i=0;i<f.length;i++){
            if (f[i]==0){
                stack[f[i]]=l[i];
            }else{
                stack[f[i]]=stack[f[i]-1]+l[i];
            }
            if (s[i].contains(".")) {
                ans = Math.max(ans, stack[f[i]] + f[i]);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution388().lengthLongestPath("dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext"));
    }
}
